<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>computed属性的get和set方法</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <div>{{fullName}}</div>
    </div>
    <script>
        var vm = new Vue({
            el: "#app",
            data: {
                firstName: "yyy",
                lastName: "ttt",
            },
            // 使用计算属性的get和set方法
            computed: {
                fullName: {
                    get: function(){
                        return this.firstName + ' ' + this.lastName;
                    },
                    set: function(value){
                        //value参数就是传入fullName改变的值 value = "aaa bbb"
                        console.log(value); // aaa bbb
                        // 通过改变fullName的值来动态改变firstName和lastName的值
                        var arr = value.split(' ');
                        this.firstName = arr[0];
                        this.lastName = arr[1];
                    }
                }
            }
        });
    </script>
</body>
</html>